package com.gpj.learn.netty.reactor.client;

import java.io.*;
import java.net.Socket;

/**
 * @className ReactorClient
 * @description TODO
 * @author GPJ
 * @date 2020/5/14 16:13
 * @version 1.0
 **/
public class ReactorClient {
    public static void main(String[] args) throws IOException {
        String hostName = "127.0.0.1";
        Integer port = 9588;
        new ReactorClient().start(hostName, port);
    }

    public void start( String hostname, int port) throws IOException {
        Socket socket = new Socket(hostname, port);

        BufferedReader socketRead = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        PrintWriter socketWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));

        BufferedReader systemRead = new BufferedReader(new InputStreamReader(System.in));
        String text;
        while ((text = systemRead.readLine()) != null){
            if("exit".equals(text)){
                break;
            }else {
                socketWriter.println(text);
                socketWriter.flush();
            }
            System.out.println("[回复]: " + socketRead.readLine());
        }
        socket.close();
    }
}
